home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Developers / src / out-of-phase-102-c / OutOfPhase 1.02 Source / OutOfPhase Folder / SymbolicDuration.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-23  |  6.2 KB  |  225 lines  |  [TEXT/KAHL]

  1. /* SymbolicDuration.c */
  2. /*****************************************************************************/
  3. /*                                                                           */
  4. /*    Out Of Phase:  Digital Music Synthesis on General Purpose Computers    */
  5. /*    Copyright (C) 1994  Thomas R. Lawrence                                 */
  6. /*                                                                           */
  7. /*    This program is free software; you can redistribute it and/or modify   */
  8. /*    it under the terms of the GNU General Public License as published by   */
  9. /*    the Free Software Foundation; either version 2 of the License, or      */
  10. /*    (at your option) any later version.                                    */
  11. /*                                                                           */
  12. /*    This program is distributed in the hope that it will be useful,        */
  13. /*    but WITHOUT ANY WARRANTY; without even the implied warranty of         */
  14. /*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          */
  15. /*    GNU General Public License for more details.                           */
  16. /*                                                                           */
  17. /*    You should have received a copy of the GNU General Public License      */
  18. /*    along with this program; if not, write to the Free Software            */
  19. /*    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.              */
  20. /*                                                                           */
  21. /*    Thomas R. Lawrence can be reached at tomlaw@world.std.com.             */
  22. /*                                                                           */
  23. /*****************************************************************************/
  24.  
  25. #include "MiscInfo.h"
  26. #include "Audit.h"
  27. #include "Debug.h"
  28. #include "Definitions.h"
  29.  
  30. #include "SymbolicDuration.h"
  31. #include "DataMunging.h"
  32. #include "NoteObject.h"
  33. #include "Memory.h"
  34. #include "SymbolicIsItInThere.h"
  35.  
  36.  
  37. /* convert the duration flags into a heap allocated string */
  38. char*                                NumericDurationToString(unsigned long Duration,
  39.                                             MyBoolean DotFlag, unsigned long Division)
  40.     {
  41.         char*                            RootString;
  42.         char*                            DotPrefix;
  43.         char*                            DivisionSuffix;
  44.         char*                            PrefixNoNull;
  45.         char*                            ResultingString;
  46.  
  47.         switch (Duration)
  48.             {
  49.                 default:
  50.                     EXECUTE(PRERR(ForceAbort,"NumericDurationToString:  bad duration value"));
  51.                     break;
  52.                 case e64thNote:
  53.                     RootString = "64th";
  54.                     break;
  55.                 case e32ndNote:
  56.                     RootString = "32nd";
  57.                     break;
  58.                 case e16thNote:
  59.                     RootString = "16th";
  60.                     break;
  61.                 case e8thNote:
  62.                     RootString = "8th";
  63.                     break;
  64.                 case e4thNote:
  65.                     RootString = "quarter";
  66.                     break;
  67.                 case e2ndNote:
  68.                     RootString = "half";
  69.                     break;
  70.                 case eWholeNote:
  71.                     RootString = "whole";
  72.                     break;
  73.                 case eDoubleNote:
  74.                     RootString = "double";
  75.                     break;
  76.                 case eQuadNote:
  77.                     RootString = "quad";
  78.                     break;
  79.             }
  80.         if (DotFlag)
  81.             {
  82.                 DotPrefix = "dotted ";
  83.             }
  84.          else
  85.             {
  86.                 DotPrefix = "";
  87.             }
  88.         switch (Division)
  89.             {
  90.                 default:
  91.                     EXECUTE(PRERR(ForceAbort,"NumericDurationToString:  bad division value"));
  92.                     break;
  93.                 case eDiv1Modifier:
  94.                     DivisionSuffix = "";
  95.                     break;
  96.                 case eDiv3Modifier:
  97.                     DivisionSuffix = " triplet";
  98.                     break;
  99.                 case eDiv5Modifier:
  100.                     DivisionSuffix = " div 5";
  101.                     break;
  102.                 case eDiv7Modifier:
  103.                     DivisionSuffix = " div 7";
  104.                     break;
  105.             }
  106.  
  107.         ResultingString = NIL;
  108.  
  109.         PrefixNoNull = StringToBlockCopy(DotPrefix);
  110.         if (PrefixNoNull != NIL)
  111.             {
  112.                 char*                            RootNoNull;
  113.  
  114.                 RootNoNull = StringToBlockCopy(RootString);
  115.                 if (RootNoNull != NIL)
  116.                     {
  117.                         char*                            FirstHalf;
  118.  
  119.                         FirstHalf = ConcatBlockCopy(PrefixNoNull,RootNoNull);
  120.                         if (FirstHalf != NIL)
  121.                             {
  122.                                 char*                            PostfixNoNull;
  123.  
  124.                                 PostfixNoNull = StringToBlockCopy(DivisionSuffix);
  125.                                 if (PostfixNoNull != NIL)
  126.                                     {
  127.                                         ResultingString = ConcatBlockCopy(FirstHalf,PostfixNoNull);
  128.                                         if (ResultingString != NIL)
  129.                                             {
  130.                                                 SetTag(ResultingString,"NumericDurationToString");
  131.                                             }
  132.                                         ReleasePtr(PostfixNoNull);
  133.                                     }
  134.                                 ReleasePtr(FirstHalf);
  135.                             }
  136.                         ReleasePtr(RootNoNull);
  137.                     }
  138.                 ReleasePtr(PrefixNoNull);
  139.             }
  140.  
  141.         return ResultingString;
  142.     }
  143.  
  144.  
  145. /* obtain duration attributes from the string passed in.  if the duration attribute */
  146. /* can't be determined, then *Duration will remain unchanged */
  147. /* this routine is kinda yucky. */
  148. void                                StringToNumericDuration(char* String, unsigned long* Duration,
  149.                                             MyBoolean* DotFlag, unsigned long* Division)
  150.     {
  151.         CheckPtrExistence(String);
  152.         ERROR((Duration == NIL) || (DotFlag == NIL) || (Division == NIL),PRERR(ForceAbort,
  153.             "StringToNumericDuration:  an output parameter is NIL"));
  154.  
  155.         /* look for hint of duration */
  156.         if (IsItInThere(String,"64") || IsItInThere(String,"sixty"))
  157.             {
  158.                 *Duration = e64thNote;
  159.             }
  160.         else if (IsItInThere(String,"32") || IsItInThere(String,"thirty"))
  161.             {
  162.                 *Duration = e32ndNote;
  163.             }
  164.         else if (IsItInThere(String,"16") || IsItInThere(String,"sixteen"))
  165.             {
  166.                 *Duration = e16thNote;
  167.             }
  168.         else if (IsItInThere(String,"8") || IsItInThere(String,"eight"))
  169.             {
  170.                 *Duration = e8thNote;
  171.             }
  172.         else if (IsItInThere(String,"4th") || IsItInThere(String,"quarter"))
  173.             {
  174.                 *Duration = e4thNote;
  175.             }
  176.         else if (IsItInThere(String,"half"))
  177.             {
  178.                 *Duration = e2ndNote;
  179.             }
  180.         else if (IsItInThere(String,"whole"))
  181.             {
  182.                 *Duration = eWholeNote;
  183.             }
  184.         else if (IsItInThere(String,"double"))
  185.             {
  186.                 *Duration = eDoubleNote;
  187.             }
  188.         else if (IsItInThere(String,"quad"))
  189.             {
  190.                 *Duration = eQuadNote;
  191.             }
  192.         else
  193.             {
  194.                 /* didn't find anything */
  195.             }
  196.  
  197.         /* look for dot hint */
  198.         if (IsItInThere(String,"dot"))
  199.             {
  200.                 *DotFlag = True;
  201.             }
  202.         else
  203.             {
  204.                 *DotFlag = False;
  205.             }
  206.  
  207.         /* look for hint of division */
  208.         if (IsItInThere(String,"div 3") || IsItInThere(String,"trip"))
  209.             {
  210.                 *Division = eDiv3Modifier;
  211.             }
  212.         else if (IsItInThere(String,"div 5") || IsItInThere(String,"quint"))
  213.             {
  214.                 *Division = eDiv5Modifier;
  215.             }
  216.         else if (IsItInThere(String,"div 7") || IsItInThere(String,"sept"))
  217.             {
  218.                 *Division = eDiv7Modifier;
  219.             }
  220.         else
  221.             {
  222.                 *Division = eDiv1Modifier;
  223.             }
  224.     }
  225.